{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "neither-sympathy",
   "metadata": {},
   "outputs": [],
   "source": [
    "from code.ftquoteapi import quoteapi \n",
    "import imp\n",
    "from futu import *\n",
    "#imp.reload(code.ftquoteapi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "previous-things",
   "metadata": {},
   "outputs": [],
   "source": [
    "context = quoteapi()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "advance-fundamental",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-05-29 09:02:35,094 [open_context_base.py] _socket_reconnect_and_wait_ready:255: Start connecting: host=127.0.0.1; port=11111;\n",
      "2021-05-29 09:02:35,096 [open_context_base.py] on_connected:344: Connected : conn_id=1; \n",
      "2021-05-29 09:02:35,192 [open_context_base.py] _handle_init_connect:445: InitConnect ok: conn_id=1; info={'server_version': 500, 'login_user_id': 716900, 'conn_id': 6804210314549199561, 'conn_key': '76556CF48A9300F3', 'conn_iv': 'BC9120E2FD6F2C93', 'keep_alive_interval': 10, 'is_encrypt': False};\n",
      "2021-05-29 09:02:35,737 [network_manager.py] work:366: Close: conn_id=1\n"
     ]
    }
   ],
   "source": [
    "context.init_context()\n",
    "ret, df = context.get_stock_basicinfo(Market.HK, SecurityType.STOCK, 'HK.00700')\n",
    "context.closecontext()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "disabled-wisconsin",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>name</th>\n",
       "      <th>lot_size</th>\n",
       "      <th>stock_type</th>\n",
       "      <th>stock_child_type</th>\n",
       "      <th>stock_owner</th>\n",
       "      <th>option_type</th>\n",
       "      <th>strike_time</th>\n",
       "      <th>strike_price</th>\n",
       "      <th>suspension</th>\n",
       "      <th>listing_date</th>\n",
       "      <th>stock_id</th>\n",
       "      <th>delisting</th>\n",
       "      <th>index_option_type</th>\n",
       "      <th>main_contract</th>\n",
       "      <th>last_trade_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HK.00700</td>\n",
       "      <td>腾讯控股</td>\n",
       "      <td>100</td>\n",
       "      <td>STOCK</td>\n",
       "      <td>N/A</td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td></td>\n",
       "      <td>N/A</td>\n",
       "      <td>N/A</td>\n",
       "      <td>2004-06-16</td>\n",
       "      <td>54047868453564</td>\n",
       "      <td>False</td>\n",
       "      <td>N/A</td>\n",
       "      <td>False</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       code  name  lot_size stock_type stock_child_type stock_owner  \\\n",
       "0  HK.00700  腾讯控股       100      STOCK              N/A               \n",
       "\n",
       "  option_type strike_time strike_price suspension listing_date  \\\n",
       "0                                  N/A        N/A   2004-06-16   \n",
       "\n",
       "         stock_id  delisting index_option_type  main_contract last_trade_time  \n",
       "0  54047868453564      False               N/A          False                  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "isolated-manhattan",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-03-01 14:35:16,014 [open_context_base.py] _socket_reconnect_and_wait_ready:255: Start connecting: host=127.0.0.1; port=11111;\n",
      "2021-03-01 14:35:16,020 [open_context_base.py] on_connected:344: Connected : conn_id=2; \n",
      "2021-03-01 14:35:16,024 [open_context_base.py] _handle_init_connect:445: InitConnect ok: conn_id=2; info={'server_version': 500, 'login_user_id': 716900, 'conn_id': 6772041516655792485, 'conn_key': '50D5CF61D89224A4', 'conn_iv': 'E2F79050835DC6D4', 'keep_alive_interval': 10, 'is_encrypt': False};\n",
      "2021-03-01 14:35:16,337 [network_manager.py] work:366: Close: conn_id=2\n"
     ]
    }
   ],
   "source": [
    "context.init_context()\n",
    "ret, dfwarrant = context.get_referencestock_list('HK.00700', SecurityReferenceType.WARRANT)\n",
    "context.closecontext()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "charged-gospel",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>lot_size</th>\n",
       "      <th>stock_type</th>\n",
       "      <th>stock_name</th>\n",
       "      <th>list_time</th>\n",
       "      <th>wrt_valid</th>\n",
       "      <th>wrt_type</th>\n",
       "      <th>wrt_code</th>\n",
       "      <th>future_valid</th>\n",
       "      <th>future_main_contract</th>\n",
       "      <th>future_last_trade_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HK.24719</td>\n",
       "      <td>1000</td>\n",
       "      <td>WARRANT</td>\n",
       "      <td>腾讯东亚九四沽A</td>\n",
       "      <td>2018-07-20</td>\n",
       "      <td>True</td>\n",
       "      <td>PUT</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HK.27886</td>\n",
       "      <td>10000</td>\n",
       "      <td>WARRANT</td>\n",
       "      <td>腾讯法兴一四购A.C</td>\n",
       "      <td>2018-09-05</td>\n",
       "      <td>True</td>\n",
       "      <td>CALL</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HK.18693</td>\n",
       "      <td>10000</td>\n",
       "      <td>WARRANT</td>\n",
       "      <td>腾讯摩通一四购A.C</td>\n",
       "      <td>2019-05-17</td>\n",
       "      <td>True</td>\n",
       "      <td>CALL</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HK.50694</td>\n",
       "      <td>5000</td>\n",
       "      <td>WARRANT</td>\n",
       "      <td>腾讯瑞银一六牛V.C</td>\n",
       "      <td>2021-01-19</td>\n",
       "      <td>True</td>\n",
       "      <td>BULL</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>HK.27227</td>\n",
       "      <td>10000</td>\n",
       "      <td>WARRANT</td>\n",
       "      <td>腾讯麦银一九购A.C</td>\n",
       "      <td>2019-09-10</td>\n",
       "      <td>True</td>\n",
       "      <td>CALL</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1693</th>\n",
       "      <td>HK.59705</td>\n",
       "      <td>5000</td>\n",
       "      <td>WARRANT</td>\n",
       "      <td>腾讯法兴一九熊L</td>\n",
       "      <td>2021-03-03</td>\n",
       "      <td>True</td>\n",
       "      <td>BEAR</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1694</th>\n",
       "      <td>HK.59708</td>\n",
       "      <td>10000</td>\n",
       "      <td>WARRANT</td>\n",
       "      <td>腾讯法兴一甲牛Z</td>\n",
       "      <td>2021-03-03</td>\n",
       "      <td>True</td>\n",
       "      <td>BULL</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1695</th>\n",
       "      <td>HK.59775</td>\n",
       "      <td>5000</td>\n",
       "      <td>WARRANT</td>\n",
       "      <td>腾讯法兴一乙牛S</td>\n",
       "      <td>2021-03-03</td>\n",
       "      <td>True</td>\n",
       "      <td>BULL</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1696</th>\n",
       "      <td>HK.59856</td>\n",
       "      <td>5000</td>\n",
       "      <td>WARRANT</td>\n",
       "      <td>腾讯中银一六熊B</td>\n",
       "      <td>2021-03-03</td>\n",
       "      <td>True</td>\n",
       "      <td>BEAR</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1697</th>\n",
       "      <td>HK.59961</td>\n",
       "      <td>5000</td>\n",
       "      <td>WARRANT</td>\n",
       "      <td>腾讯瑞通一甲牛C</td>\n",
       "      <td>2021-03-03</td>\n",
       "      <td>True</td>\n",
       "      <td>BULL</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1698 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          code  lot_size stock_type  stock_name   list_time  wrt_valid  \\\n",
       "0     HK.24719      1000    WARRANT    腾讯东亚九四沽A  2018-07-20       True   \n",
       "1     HK.27886     10000    WARRANT  腾讯法兴一四购A.C  2018-09-05       True   \n",
       "2     HK.18693     10000    WARRANT  腾讯摩通一四购A.C  2019-05-17       True   \n",
       "3     HK.50694      5000    WARRANT  腾讯瑞银一六牛V.C  2021-01-19       True   \n",
       "4     HK.27227     10000    WARRANT  腾讯麦银一九购A.C  2019-09-10       True   \n",
       "...        ...       ...        ...         ...         ...        ...   \n",
       "1693  HK.59705      5000    WARRANT    腾讯法兴一九熊L  2021-03-03       True   \n",
       "1694  HK.59708     10000    WARRANT    腾讯法兴一甲牛Z  2021-03-03       True   \n",
       "1695  HK.59775      5000    WARRANT    腾讯法兴一乙牛S  2021-03-03       True   \n",
       "1696  HK.59856      5000    WARRANT    腾讯中银一六熊B  2021-03-03       True   \n",
       "1697  HK.59961      5000    WARRANT    腾讯瑞通一甲牛C  2021-03-03       True   \n",
       "\n",
       "     wrt_type  wrt_code  future_valid  future_main_contract  \\\n",
       "0         PUT  HK.00700         False                   NaN   \n",
       "1        CALL  HK.00700         False                   NaN   \n",
       "2        CALL  HK.00700         False                   NaN   \n",
       "3        BULL  HK.00700         False                   NaN   \n",
       "4        CALL  HK.00700         False                   NaN   \n",
       "...       ...       ...           ...                   ...   \n",
       "1693     BEAR  HK.00700         False                   NaN   \n",
       "1694     BULL  HK.00700         False                   NaN   \n",
       "1695     BULL  HK.00700         False                   NaN   \n",
       "1696     BEAR  HK.00700         False                   NaN   \n",
       "1697     BULL  HK.00700         False                   NaN   \n",
       "\n",
       "      future_last_trade_time  \n",
       "0                        NaN  \n",
       "1                        NaN  \n",
       "2                        NaN  \n",
       "3                        NaN  \n",
       "4                        NaN  \n",
       "...                      ...  \n",
       "1693                     NaN  \n",
       "1694                     NaN  \n",
       "1695                     NaN  \n",
       "1696                     NaN  \n",
       "1697                     NaN  \n",
       "\n",
       "[1698 rows x 11 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfwarrant"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "neither-calculation",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-03-01 14:37:15,694 [open_context_base.py] _socket_reconnect_and_wait_ready:255: Start connecting: host=127.0.0.1; port=11111;\n",
      "2021-03-01 14:37:15,698 [open_context_base.py] on_connected:344: Connected : conn_id=4; \n",
      "2021-03-01 14:37:15,702 [open_context_base.py] _handle_init_connect:445: InitConnect ok: conn_id=4; info={'server_version': 500, 'login_user_id': 716900, 'conn_id': 6772042018643419666, 'conn_key': 'FE748662D8927020', 'conn_iv': '5ED8B097A35D56B9', 'keep_alive_interval': 10, 'is_encrypt': False};\n",
      "2021-03-01 14:37:15,779 [network_manager.py] work:366: Close: conn_id=4\n"
     ]
    }
   ],
   "source": [
    "context.init_context()\n",
    "ret, dffuture = context.get_referencestock_list('HK.A50main', SecurityReferenceType.FUTURE)\n",
    "context.closecontext()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "virgin-extra",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>lot_size</th>\n",
       "      <th>stock_type</th>\n",
       "      <th>stock_name</th>\n",
       "      <th>list_time</th>\n",
       "      <th>wrt_valid</th>\n",
       "      <th>wrt_type</th>\n",
       "      <th>wrt_code</th>\n",
       "      <th>future_valid</th>\n",
       "      <th>future_main_contract</th>\n",
       "      <th>future_last_trade_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HK.A50main</td>\n",
       "      <td>5000</td>\n",
       "      <td>FUTURE</td>\n",
       "      <td>安硕富时 A50 ETF主连(2103)</td>\n",
       "      <td></td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HK.A502102</td>\n",
       "      <td>5000</td>\n",
       "      <td>FUTURE</td>\n",
       "      <td>安硕富时 A50 ETF2102</td>\n",
       "      <td></td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>2021-02-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HK.A502103</td>\n",
       "      <td>5000</td>\n",
       "      <td>FUTURE</td>\n",
       "      <td>安硕富时 A50 ETF2103</td>\n",
       "      <td></td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>2021-03-30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HK.A502104</td>\n",
       "      <td>5000</td>\n",
       "      <td>FUTURE</td>\n",
       "      <td>安硕富时 A50 ETF2104</td>\n",
       "      <td></td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>2021-04-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>HK.A502105</td>\n",
       "      <td>5000</td>\n",
       "      <td>FUTURE</td>\n",
       "      <td>安硕富时 A50 ETF2105</td>\n",
       "      <td></td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>2021-05-28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>HK.A502106</td>\n",
       "      <td>5000</td>\n",
       "      <td>FUTURE</td>\n",
       "      <td>安硕富时 A50 ETF2106</td>\n",
       "      <td></td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>2021-06-29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>HK.A502109</td>\n",
       "      <td>5000</td>\n",
       "      <td>FUTURE</td>\n",
       "      <td>安硕富时 A50 ETF2109</td>\n",
       "      <td></td>\n",
       "      <td>False</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>2021-09-29</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         code  lot_size stock_type            stock_name list_time  wrt_valid  \\\n",
       "0  HK.A50main      5000     FUTURE  安硕富时 A50 ETF主连(2103)                False   \n",
       "1  HK.A502102      5000     FUTURE      安硕富时 A50 ETF2102                False   \n",
       "2  HK.A502103      5000     FUTURE      安硕富时 A50 ETF2103                False   \n",
       "3  HK.A502104      5000     FUTURE      安硕富时 A50 ETF2104                False   \n",
       "4  HK.A502105      5000     FUTURE      安硕富时 A50 ETF2105                False   \n",
       "5  HK.A502106      5000     FUTURE      安硕富时 A50 ETF2106                False   \n",
       "6  HK.A502109      5000     FUTURE      安硕富时 A50 ETF2109                False   \n",
       "\n",
       "   wrt_type  wrt_code  future_valid  future_main_contract  \\\n",
       "0       NaN       NaN          True                  True   \n",
       "1       NaN       NaN          True                 False   \n",
       "2       NaN       NaN          True                 False   \n",
       "3       NaN       NaN          True                 False   \n",
       "4       NaN       NaN          True                 False   \n",
       "5       NaN       NaN          True                 False   \n",
       "6       NaN       NaN          True                 False   \n",
       "\n",
       "  future_last_trade_time  \n",
       "0                         \n",
       "1             2021-02-25  \n",
       "2             2021-03-30  \n",
       "3             2021-04-29  \n",
       "4             2021-05-28  \n",
       "5             2021-06-29  \n",
       "6             2021-09-29  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dffuture"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "outstanding-framing",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2021-03-01 14:43:12,676 [open_context_base.py] _socket_reconnect_and_wait_ready:255: Start connecting: host=127.0.0.1; port=11111;\n",
      "2021-03-01 14:43:12,679 [open_context_base.py] on_connected:344: Connected : conn_id=1; \n",
      "2021-03-01 14:43:12,684 [open_context_base.py] _handle_init_connect:445: InitConnect ok: conn_id=1; info={'server_version': 500, 'login_user_id': 716900, 'conn_id': 6772043515941211858, 'conn_key': '482BA764D8922CB4', 'conn_iv': '91C1FBAEE95D06E9', 'keep_alive_interval': 10, 'is_encrypt': False};\n",
      "2021-03-01 14:43:12,731 [network_manager.py] work:366: Close: conn_id=1\n"
     ]
    }
   ],
   "source": [
    "context.init_context()\n",
    "data_filter = OptionDataFilter()\n",
    "data_filter.delta_min = 0.4\n",
    "data_filter.delta_max = 0.6\n",
    "ret, data = context.get_option_chain('HK.00700', IndexOptionType.NORMAL, '2021-03-01', '2021-03-30', OptionType.ALL, OptionCondType.ALL, data_filter)\n",
    "context.closecontext()"
   ]
  },
  {
   "cell_type": "raw",
   "id": "micro-cincinnati",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "upset-overview",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>name</th>\n",
       "      <th>lot_size</th>\n",
       "      <th>stock_type</th>\n",
       "      <th>option_type</th>\n",
       "      <th>stock_owner</th>\n",
       "      <th>strike_time</th>\n",
       "      <th>strike_price</th>\n",
       "      <th>suspension</th>\n",
       "      <th>stock_id</th>\n",
       "      <th>index_option_type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>HK.TCH210330C680000</td>\n",
       "      <td>腾讯 210330 680.00 购</td>\n",
       "      <td>100</td>\n",
       "      <td>DRVT</td>\n",
       "      <td>CALL</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>2021-03-30</td>\n",
       "      <td>680.0</td>\n",
       "      <td>False</td>\n",
       "      <td>80156795</td>\n",
       "      <td>N/A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HK.TCH210330C690000</td>\n",
       "      <td>腾讯 210330 690.00 购</td>\n",
       "      <td>100</td>\n",
       "      <td>DRVT</td>\n",
       "      <td>CALL</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>2021-03-30</td>\n",
       "      <td>690.0</td>\n",
       "      <td>False</td>\n",
       "      <td>80156872</td>\n",
       "      <td>N/A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>HK.TCH210330C700000</td>\n",
       "      <td>腾讯 210330 700.00 购</td>\n",
       "      <td>100</td>\n",
       "      <td>DRVT</td>\n",
       "      <td>CALL</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>2021-03-30</td>\n",
       "      <td>700.0</td>\n",
       "      <td>False</td>\n",
       "      <td>80156987</td>\n",
       "      <td>N/A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>HK.TCH210330C710000</td>\n",
       "      <td>腾讯 210330 710.00 购</td>\n",
       "      <td>100</td>\n",
       "      <td>DRVT</td>\n",
       "      <td>CALL</td>\n",
       "      <td>HK.00700</td>\n",
       "      <td>2021-03-30</td>\n",
       "      <td>710.0</td>\n",
       "      <td>False</td>\n",
       "      <td>80157260</td>\n",
       "      <td>N/A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  code                name  lot_size stock_type option_type  \\\n",
       "0  HK.TCH210330C680000  腾讯 210330 680.00 购       100       DRVT        CALL   \n",
       "1  HK.TCH210330C690000  腾讯 210330 690.00 购       100       DRVT        CALL   \n",
       "2  HK.TCH210330C700000  腾讯 210330 700.00 购       100       DRVT        CALL   \n",
       "3  HK.TCH210330C710000  腾讯 210330 710.00 购       100       DRVT        CALL   \n",
       "\n",
       "  stock_owner strike_time  strike_price  suspension  stock_id  \\\n",
       "0    HK.00700  2021-03-30         680.0       False  80156795   \n",
       "1    HK.00700  2021-03-30         690.0       False  80156872   \n",
       "2    HK.00700  2021-03-30         700.0       False  80156987   \n",
       "3    HK.00700  2021-03-30         710.0       False  80157260   \n",
       "\n",
       "  index_option_type  \n",
       "0               N/A  \n",
       "1               N/A  \n",
       "2               N/A  \n",
       "3               N/A  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "thrown-decimal",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
